Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pickers] Remove utils and value params from translations #14986

Conversation

arthurbalduini
Copy link
Member

@arthurbalduini arthurbalduini commented Oct 15, 2024

Changelog

Pickers

  • Some translation keys no longer require utils and the date object as parameters, but only the formatted value as a string. The keys affected by this changes are: clockLabelText, openDatePickerDialogue and openTimePickerDialogue.
    If you have customized those translation keys, you have to update them following the examples below:

    • If you are setting a custom value in a picker component:
    -clockLabelText: (view, time, utils) =>
    -   `Select ${view}. ${
    -     time === null || !utils.isValid(time)
    -       ? 'No time selected'
    -       : `Selected time is ${utils.format(time, 'fullTime')}`
    -   }`
    +clockLabelText: (view, formattedTime) =>
    +   `Select ${view}. ${
    +     formattedTime == null ? 'No time selected' : `Selected time is ${formattedTime}`
    +   }`
    
    -openDatePickerDialogue: (value, utils) =>
    -  value !== null && utils.isValid(value)
    -    ? `Choose date, selected date is ${utils.format(value, 'fullDate')}`
    -    : 'Choose date',
    +openDatePickerDialogue: (formattedDate) =>
    +  formattedDate ? `Choose date, selected date is ${formattedDate}` : 'Choose date'
    
    -openTimePickerDialogue: (value, utils) =>
    -  value !== null && utils.isValid(value)
    -    ? `Choose time, selected time is ${utils.format(value, 'fullTime')}`
    -    : 'Choose time',
    +openTimePickerDialogue: (formattedTime) =>
    +  formattedTime ? `Choose time, selected time is ${formattedTime}` : 'Choose time'
    • If you are setting a custom value in the LocalizationProvider:
     <LocalizationProvider localeText={{
    -   clockLabelText: (view, time, utils) =>
    -     `Select ${view}. ${
    -       time === null || !utils.isValid(time)
    -         ? 'No time selected'
    -         : `Selected time is ${utils.format(time, 'fullTime')}`
    -     }`
    +   clockLabelText: (view, formattedTime) =>
    +     `Select ${view}. ${
    +       formattedTime == null ? 'No time selected' : `Selected time is ${formattedTime}`
    +     }`
    -   openDatePickerDialogue: (value, utils) =>
    -     value !== null && utils.isValid(value)
    -      ? `Choose date, selected date is ${utils.format(value, 'fullDate')}`
    -      : 'Choose date',
    +   openDatePickerDialogue: (formattedDate) =>
    +     formattedDate ? `Choose date, selected date is ${formattedDate}` : 'Choose date'
    -   openTimePickerDialogue: (value, utils) =>
    -     value !== null && utils.isValid(value)
    -       ? `Choose time, selected time is ${utils.format(value, 'fullTime')}`
    -       : 'Choose time',
    +   openTimePickerDialogue: (formattedTime) =>
    +     formattedTime ? `Choose time, selected time is ${formattedTime}` : 'Choose time'
     }} >
    • If you using this translation key in a custom component:
     const translations = usePickersTranslations();
    
    -const clockLabelText = translations.clockLabelText(
    -  view,
    -  value,
    -  {} as any,
    -  value == null ? null : value.format('hh:mm:ss')
    -);
    +const clockLabelText = translations.clockLabelText(
    +  view,
    +  value == null ? null : value.format('hh:mm:ss')
    +);
    
    -const openDatePickerDialogue = translations.openDatePickerDialogue(
    -  value,
    -  {} as any,
    -  value == null ? null : value.format('MM/DD/YYY')
    -);
    +const openDatePickerDialogue = translations.openDatePickerDialogue(
    +  value == null ? null : value.format('MM/DD/YYY')
    +);
    
    -const openTimePickerDialogue = translations.openTimePickerDialogue(
    -  value,
    -  {} as any,
    -  value == null ? null : value.format('hh:mm:ss')
    -);
    +const openTimePickerDialogue = translations.openTimePickerDialogue(
    +  value == null ? null : value.format('hh:mm:ss')
    +);

@arthurbalduini arthurbalduini added breaking change component: pickers This is the name of the generic UI component, not the React module! v8.x labels Oct 15, 2024
@mui-bot
Copy link

mui-bot commented Oct 15, 2024

Localization writing tips ✍️

Seems you are updating localization 🌍 files.

Thank you for contributing to the localization! 🎉 To make your PR perfect, here is a list of elements to check: ✔️

  • Verify if the PR title respects the release format. Here are two examples (depending if you update or add a locale file)

    [l10n] Improve Swedish (sv-SE) locale
    [l10n] Add Danish (da-DK) locale

  • Update the documentation of supported locales by running pnpm l10n
  • Clean files with pnpm prettier.

Deploy preview: https://deploy-preview-14986--material-ui-x.netlify.app/

Updated pages:

Generated by 🚫 dangerJS against d88e457

@arthurbalduini arthurbalduini mentioned this pull request Oct 15, 2024
12 tasks
Copy link
Member

@flaviendelangle flaviendelangle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work 🙏

Can you take care of adding the migration guide (you can copy paste the doc page from #14651 and just replace the actual sections)?

Don't forget the small BC on PickersInputLocaleText which is public 👍

No codemod required here IMHO

@arthurbalduini
Copy link
Member Author

Don't forget the small BC on PickersInputLocaleText which is public 👍

I also mentioned other exported types that no longer receive a parameter.

Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 22, 2024
@arthurbalduini arthurbalduini marked this pull request as ready for review October 23, 2024 12:41
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 23, 2024
arthurbalduini and others added 3 commits October 23, 2024 16:24
Co-authored-by: Flavien DELANGLE <flaviendelangle@gmail.com>
Signed-off-by: Arthur Suh Balduini <34691066+arthurbalduini@users.noreply.github.com>
+const openDatePickerDialogue = translations.openDatePickerDialogue(value == null ? null : value.format('MM/DD/YYY'));
```

Notice that `clockLabelText` expects an additional parameter with the time view.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest just doing on diff per translation key.
The migration guide can be very lengthy if it helps people migrate (see this section for a very long migration content 😆 )

So something like:

The following translation key no longer receive the `utils` and the date object:

- `openDatePickerDialogue`:

  ```diff
  // If you are setting a custom value for this translation key in a picker component or in the `LocalizationProvider`
  -<DatePicker localeText={{ openDatePickerDialogue: (date, utils) => string; }} />
  +<DatePicker localeText={{ openDatePickerDialogue: (formattedDate) => string; }} />

  // If you using this translation key in a custom component
   const translations = useTranslations();
  -const openDatePickerDialogue = translations.openTimePickerDialogue(value, {} as any, value == null ? null : value.format('MM/DD/YYY'));
  +const openDatePickerDialogue = translations.openDatePickerDialogue(value == null ? null : value.format('MM/DD/YYY'));
  ```

  - `openTimePickerDialogue`:

  ```diff
  ```

@arthurbalduini arthurbalduini force-pushed the remove-utils-and-value-params-from-translations branch from ccc6bbe to d613f50 Compare October 25, 2024 16:03
Copy link
Member

@LukasTy LukasTy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you for handling it. 🙏

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 28, 2024
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 28, 2024
Copy link
Member

@LukasTy LukasTy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for taking care of it. 🙏

Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 29, 2024
Copy link
Member

@flaviendelangle flaviendelangle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the very detailed migration guide 🙏

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 29, 2024
@arthurbalduini arthurbalduini merged commit 5b553c8 into mui:master Oct 29, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change component: pickers This is the name of the generic UI component, not the React module! v8.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants